<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\Renting;
use Illuminate\Http\Request;

class UserController extends Controller
{
    //
    public function userinfo(Request $request)
    {
        //得到openid
        $openid = $request->get('openid');
        //得到表单数据 头像 和 昵称
        $data = $request->except('openid');
        //修改入库
        Renting::where('openid',$openid)->update($data);
        return ['status'=>0,'msg'=>'修改成功'];
    }
    //获取信息
    public function getuserinfo(Request $request)
    {
        //得到openid
        $openid = $request->get('openid');
        return Renting::where('openid',$openid)->first();
    }
    //文件上传
    public function upfile(Request $request)
    {
        if($request->hasFile('file')){
            //上传
            //参数2 配置的节点名称
            $ret = $request->file('file')->store('','card');
            $pic = '/uploads/card/'.$ret;
            return ['status'=>0,'pic'=>$pic];
        }
        return ['status'=>10005,'msg'=>'无图片上传'];
    }
}
